package com.my.main.controller.sysConfig;


import com.my.main.base.entity.Result;
import com.my.main.base.entity.ResultCode;
import com.my.main.common.utils.CurrencyUtil;
import com.my.main.entity.sysConfig.SysAuditLog;
import com.my.main.service.sysConfig.SysAuditLogService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 系统配置--审计日志
 *
 * @author liuhx 2020-04-29
 */


//1.解决跨域
@CrossOrigin
//2.声明restContoller
@RestController
//3.设置父路径
@RequestMapping(value="/api/v1/sys/SysAuditLog")
public class SysAuditLogController {

    @Autowired
    private SysAuditLogService sysAuditLogService;

    /**
     *  查询 - 查询审计日志列表
     *
     * @param map
     *
     * @author liuhx 2020-04-28
     */
    @ApiOperation(value="系统配置 - 查询审计日志列表")
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    public Result saveSysConfigCode(@RequestBody Map<String, Object> map) {

        Map<String, Object> resMap = new HashMap<>();
        resMap.put("page", map.get("page"));
        resMap.put("limit", map.get("limit"));

        try {
            // 查询总条数
            resMap.put("totalCount", sysAuditLogService.queryCount());

            List<Map<String, Object>> resList = new ArrayList<>();

            map.put("page", CurrencyUtil.PageRowNum(Integer.parseInt(map.get("page").toString()), Integer.parseInt(map.get("limit").toString())));
            List<SysAuditLog> sysAuditLogList = sysAuditLogService.queryList(map);
            resMap.put("sysAuditLogList", sysAuditLogList);
            return new Result(ResultCode.SUCCESS, resMap);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(ResultCode.SERVER_ERROR);
        }
    }
}
